package com.whut.mobilesafe.utils;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;

import java.util.List;

/**
 * 作    者:yubo.xiaoyubo
 * 时    间：2015/12/27 10:06
 * 版    本：1.0
 * 描    述：关于服务的相关的工具
 */
public class ServiceUtils {

    public static boolean isServiceRunning(Context context, String serviceName) {
        boolean flag = false;
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningServiceInfo> services = activityManager.getRunningServices(100);
        for (RunningServiceInfo info : services) {
            String className = info.service.getClassName();
            if (className.equals(serviceName)) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
